{extend name="sitehome@style/base"/}
{block name="main"}
<div class="layui-form">
  <div class="layui-form-item">
    <label class="layui-form-label"><span class="required">*</span>应用APPID</label>
    <div class="layui-input-inline nc-len-long">
      <input type="text" required lay-verify="required" placeholder="请输入APPID" readonly value="{$wechat_config['appid']}" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"><span class="required">*</span>应用密钥AppSecret</label>
    <div class="layui-input-inline nc-len-long">
      <input type="text" required  lay-verify="required" placeholder="请输入AppSecret" readonly  value="{$wechat_config['appsecret']}" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" ><span class="required">*</span>支付签名串API密钥</label>
    <div class="layui-input-inline nc-len-long">
      <input type="text" name="app_paysignkey" required  lay-verify="required" placeholder="请输入paySignKey" {notempty name="$config"}value="{$config['app_paysignkey']}"{/notempty} autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" ><span class="required">*</span>微信支付商户号</label>
    <div class="layui-input-inline nc-len-long">
      <input type="text" name="mchid" required  lay-verify="required" placeholder="请输入商户号MCHID" {notempty name="$config"}value="{$config['mchid']}"{/notempty} autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"><span class="required">*</span>apiclient_cert</label>
    <div class="layui-input-inline nc-len-long">
      <input type="text" name="apiclient_cert" required  lay-verify="required" placeholder="请输入绝对路径" {notempty name="$config"}value="{$config['apiclient_cert']}"{/notempty} autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"><span class="required">*</span>apiclient_key.pem</label>
    <div class="layui-input-inline nc-len-long">
      <input type="text" name="apiclient_key" required lay-verify="required" placeholder="请输入绝对路径" {notempty name="$config"}value="{$config['apiclient_key']}"{/notempty} autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">是否启用支付</label>
    <div class="layui-input-inline">
      <input type="checkbox" required name="pay_status" value="1" lay-skin="switch" {if condition='!empty($config) && $config.pay_status' eq 1}checked{/if}>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">是否启用退款</label>
    <div class="layui-input-inline">
      <input type="checkbox" required name="refund_is_use" value="1" lay-skin="switch" {if condition='!empty($config) && $config.refund_is_use' eq 1}checked{/if}>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">是否启用转账</label>
    <div class="layui-input-inline">
      <input type="checkbox" required name="transfer_is_use" value="1" lay-skin="switch" {if condition='!empty($config) && $config.transfer_is_use' eq 1}checked{/if}>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label" >是否启用</label>
    <div class="layui-input-inline">
      <input type="checkbox" required name="status" value="1" lay-skin="switch" lay-filter="switchTest" {if condition='$status' eq 1}checked{/if}>
    </div>
  </div>
  <div class="nc-form-row">
      <button class="layui-btn" lay-submit lay-filter="savePay">保存</button>
      <a href="javascript:history.back(-1);" class="layui-btn layui-btn-primary">返回</a>
  </div>
</div>
 
<script>
layui.use('form', function() {
	var form = layui.form;
	var repeat_flag = false;//防重复标识
	form.on('submit(savePay)', function (data) {
		var field = data.field;
		if (repeat_flag) return;
		repeat_flag = true;
		$.ajax({
			type: "post",
			url: '{:addon_url("PayWechat://sitehome/payconfig/index")}',
			data: field,
			dataType: "JSON",
			success: function (res) {
				layer.msg(res.message);
				if (res.code == 0) {
					location.reload();
				}else{
					repeat_flag = false;
				}
			}
		});
	});
});

$("#resets").click(function(){
	$(":input[type='text']").attr('value', '');
	$(":input[type='checkbox']").prop('checked',false).removeAttr('checked');
});
</script>
{/block}